/**
 * 	 Copyright (c) 2008, 2009 Lukas Zaruba
 * 
 *   This file is part of UniAnalyzer (Universal Analyzer).
 *
 *   UniAnalyzer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   UniAnalyzer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with UniAnalyzer. If not, see <http://www.gnu.org/licenses/>.
 */

package net.zarubsys.unianalyzer.dataminers.lpt.pin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * PinHelper
 *
 * @author  &lt;A HREF=&quot;mailto:lukas.zaruba@media-solutions.cz&quot;&gt;Lukas Zaruba&lt;/A&gt;, MEDIA SOLUTIONS CZECH REPUBLIC Ltd.
 * @version $Revision$ $Date$
 */
public class PinHelper {
	private static final PinHelper INSTANCE = new PinHelper();
	public static final String reservedLabel = "reserved"; //$NON-NLS-1$
	
	public List<Pin> getPinsOnOffset(int offset) {
		Pin[] pins = Pin.values();
		List<Pin> result = new ArrayList<Pin>(8);
		
		for (int i = 0; i < pins.length; i++) {
			Pin p = pins[i];
			if (p.getOffset() == offset) {
				result.add(p);
			}
		}
		Collections.sort(result, new Comparator<Pin>() {

			public int compare(Pin arg0, Pin arg1) {
				return arg0.getOrderInByte() - arg1.getOrderInByte(); 
			}
			
		});
		return Collections.unmodifiableList(result);
	}
	
	public List<CustomizedPin> getCheckedPins(List<CustomizedPin> original) {
		List<CustomizedPin> result = new ArrayList<CustomizedPin>(8);
		
		for (CustomizedPin pin : original) {
			if (pin.isChecked() && !pin.isReserved()) {
				result.add(pin);
			}
		}
		return result;
	}
	
	public String[] convertCustomizedPinsToStrings(List<CustomizedPin> pins) {
		List<String> result = new ArrayList<String>(8);
		for (CustomizedPin pin : pins) {
			result.add(pin.getCustomizedLabel());
		}
		return result.toArray(new String[0]);
	}
	
	public static PinHelper getInstance() {
		return INSTANCE;
	}

}


/*
 * $Log$
 */